Winform/WPF嵌入其他指定进程
/// <summary>
/// 将指定的程序嵌入指定的控件
/// </summary>
public void EmbedProcess(IntPtr mainHandle, Control control)
{
// Get the main handle
if (mainHandle == IntPtr.Zero || control == null) return;
try
{
// Put it into this form
SetParent(mainHandle, control.Handle);
// Remove border and whatnot
SetWindowLong(new HandleRef(this, mainHandle), GWL_STYLE, WS_VISIBLE);
ShowWindow(mainHandle, (int)ProcessWindowStyle.Maximized);
bool move = MoveWindow(mainHandle, 0, 0, control.Width, control.Height, true);
control.Invalidate();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
评论